﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace Admin
{
    class DataSourceSelector : System.ComponentModel.StringConverter
    {
        private List<string> DataSrcList = new List<string>();
        public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context)
        {
            return true; // true = we support standard types
        }

        public override StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
        {
            DataSrcList.Clear();
            DataSrcList.Add("Только просмотр");
            DataSrcList.Add("Полные"); 
           
            return new StandardValuesCollection(DataSrcList);
        }

        public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context)
        {
            return true;// true = user can select values from list only
        }

    }
 
    public class loginVisual
    {
        static string getMd5Hash(string input)
        {
            // Create a new instance of the MD5CryptoServiceProvider object.
            MD5 md5Hasher = MD5.Create();
            // Convert the input string to a byte array and compute the hash.
            byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder sBuilder = new StringBuilder();
            // Loop through each byte of the hashed data 
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            // Return the hexadecimal string.
            return sBuilder.ToString();
        }
        [DisplayName("Логин")]
        [Description("Лоин")]
        [Category("Оснвное")]
        public string user { get; set; }
        [Description("Пароль")]
        [DisplayName("Пароль")]
        [Category("Оснвное")]
        [PasswordPropertyText(true)]
        public string passv {
            get { return pass; }
            set { pass = getMd5Hash(value.TrimStart().TrimEnd()); }
        }
        [Description("Права")]
        [DisplayName("Права")]
        [Category("Оснвное")]
        [TypeConverter(typeof(DataSourceSelector))]
        public string type { get; set; }
        [Browsable(false)]
         public string pass {get; set;}
    }
}
